package br.com.cliquetroca.dao;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

public class GenericDao<T> {
	protected final HibernateTemplate template;
	private final Class<T> persistentClass;

	public GenericDao(final HibernateTemplate template, final Class<T> persistentClass) {
		this.template = template;
		this.persistentClass = persistentClass;
	}
	
	@Transactional
	public void delete(final T o) {
		template.delete(o);
	}

	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
	public T findByPk(final Serializable pk) {
		return (T) template.get(persistentClass, pk);
	}

	@Transactional
	public Serializable save(final T o) {
		return template.save(o);
	}

	public List<T> list() {
		return null;
	}
}